find_package(FLEX)
find_package(BISON)
if(BISON_FOUND AND FLEX_FOUND)
  bison_target(ruleparser ruleparser.y ${CMAKE_CURRENT_BINARY_DIR}/ruleparser.c COMPILE_FLAGS "--defines=${CMAKE_CURRENT_BINARY_DIR}/ruleparser.yy.h")
  flex_target(token token.l ${CMAKE_CURRENT_BINARY_DIR}/token.c COMPILE_FLAGS "--header-file=${CMAKE_CURRENT_BINARY_DIR}/lex.yy.h")
  add_flex_bison_dependency(token ruleparser)
  include_directories(${CMAKE_CURRENT_BINARY_DIR})
  include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  add_library(dbfwfilter SHARED dbfwfilter.c ${BISON_ruleparser_OUTPUTS} ${FLEX_token_OUTPUTS})
  target_link_libraries(dbfwfilter maxscale-common)
  set_target_properties(dbfwfilter PROPERTIES VERSION "1.0.0")
  install(TARGETS dbfwfilter DESTINATION ${MAXSCALE_LIBDIR})

  if(BUILD_TOOLS)
    add_executable(dbfwruleparser dbfwfilter.c ${BISON_ruleparser_OUTPUTS} ${FLEX_token_OUTPUTS})
    target_compile_definitions(dbfwruleparser PUBLIC "BUILD_RULE_PARSER")
    target_link_libraries(dbfwruleparser maxscale-common)
    install(TARGETS dbfwruleparser DESTINATION ${MAXSCALE_BINDIR})
  endif()
else()
    message(FATAL_ERROR "Could not find Bison or Flex: ${BISON_EXECUTABLE} ${FLEX_EXECUTABLE}")
endif()
